package com.bins.mongodb.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.bins.mongodb.entity.UserEntity;
import com.bins.mongodb.service.UserService;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/mongo/save")
    public String saveUser(@RequestBody UserEntity user) {return userService.saveUser(user);}

    @GetMapping("/mongo/findAll")
    public List<UserEntity> findAll() {return userService.findAll();}

    @GetMapping("/mongo/findOne")
    public UserEntity findOne(@RequestParam Long id) {return userService.getUserById(id);}

    @PostMapping("/mongo/update")
    public String update(@RequestBody UserEntity user) {return userService.updateUser(user);}

    @PostMapping("/mongo/delOne")
    public String delOne(@RequestBody UserEntity user) {return userService.deleteUser(user);}

    @GetMapping("/mongo/delById")
    public String delById(@RequestParam Long id) {return userService.deleteUserById(id);}
}